package com.oa.pm.controller;

import com.joneying.common.annotation.CommonController;
import com.joneying.common.web.response.Resp;
import com.oa.core.BaseController;
import com.oa.core.PageResult;
import com.oa.core.exception.BusinessException;
import com.oa.core.exception.DataIsEmptyException;
import com.oa.pm.service.IPostponedLeaveApplyService;
import com.oa.pm.vo.PostponedLeaveApplyListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.web.bind.annotation.*;

@Api(description = "延后休假")
@RequestMapping("/postponedLeaveApply")
@RestController
public class PostponedLeaveApplyController extends BaseController {

    @Autowired
    public IPostponedLeaveApplyService postponedLeaveApplyService;

    @GetMapping("/list")
    @CommonController
    @Description("列表")
    @ApiOperation(value = "列表")
    public Resp<PageResult<PostponedLeaveApplyListVO>> findPostponedLeaveApplyList(@RequestParam Integer pageNum, @RequestParam  Integer pageSize, @RequestParam(required = false)  String name){
        return new Resp().success(postponedLeaveApplyService.findPostponedLeaveApplyList(pageNum, pageSize, getLoginUserId(), name));
    }

    @GetMapping("/{id}")
    @CommonController
    @Description("根据ID")
    @ApiOperation(value = "根据ID")
    public Resp<PostponedLeaveApplyListVO> findPostponedLeaveApplyDetails(@PathVariable String id){
        return new Resp().success(postponedLeaveApplyService.findPostponedLeaveApplyDetails(id));
    }

    @PostMapping("")
    @CommonController
    @Description("根据ID")
    @ApiOperation(value = "根据ID")
    public Resp add(String remark) throws BusinessException, DataIsEmptyException {
        return postponedLeaveApplyService.add(getLoginUserId(), remark);
    }

    @PutMapping("/audit")
    @CommonController
    @Description("审核")
    @ApiOperation(value = "审核")
    public Resp audit(@RequestParam String id, @RequestParam Integer status) throws BusinessException, DataIsEmptyException {
        return postponedLeaveApplyService.audit(getLoginUserId(), id, status);
    }
}
